import { Steps } from 'nextra/components'
import { Callout } from 'nextra/components'

# Self Hosting Guide

This guide will walk you through setting up your own instance of Rybbit.

## Prerequisites

Before you begin, ensure you have the following:

-   **A Linux VPS:** Try to get one with at least 2GB of RAM.

    We use Hetzner for everything. [Use our referral link](https://hetzner.cloud/?ref=QEdVqVpTLBDP) to get a 20 dollars of credits. It should last you almost half a year. The AMD CX11 is a good choice for ~$4/month.
    
-   **A Domain Name:** You'll need a domain or subdomain (e.g., `tracking.yourdomain.com`) pointed to your VPS's IP address. HTTPS is required because browsers block tracking scripts served over insecure HTTP.
-   **Git:** Needed to clone the repository.

<Callout type="info">
  This guide has been tested on Ubuntu 24 LTS and currently does not work on ARM architectures. We will add support for ARM soon.
</Callout>

## Setup Steps

<Steps>
### 1. Point Your Domain to Your VPS

Configure your domain's DNS settings to point to your VPS's public IP address. This usually involves:

1.  Finding your VPS's public IPv4 address (from your hosting provider, e.g., Hetzner).
2.  Logging into your domain registrar or DNS provider (e.g., GoDaddy, Namecheap, Cloudflare).
3.  Adding an `A` record:
    *   **Host/Name:** Your desired subdomain (e.g., `tracking`) or `@` for the root domain.
    *   **Value:** Your VPS's IPv4 address.
    *   **TTL:** Default or a low value (e.g., 300 seconds) for faster updates.

DNS changes might take some time to propagate globally. Use [DNS Checker](https://dnschecker.org/) to verify.

### 2. Install Docker Engine

Connect to your VPS via SSH.

Follow the official Docker Engine installation instructions for your Linux distribution:
[https://docs.docker.com/engine/install/](https://docs.docker.com/engine/install/)

### 3. Clone the Rybbit Repository

Clone the project repository from GitHub (Git is usually pre-installed on most server distributions):
```bash
git clone https://github.com/rybbit-io/rybbit.git
cd rybbit
```

### 4. Run the Setup Script

The repository includes a setup script that configures the necessary environment variables (including generating a secure secret) and starts the application using Docker Compose.

<Callout type="warning">
  Important: Make all scripts executable before proceeding!
  ```bash
  chmod +x *.sh
  ```
</Callout>

Run the setup script, replacing `your.domain.name` with the domain or subdomain you configured in the prerequisites:
```bash
./setup.sh your.domain.name
```

The script will create a `.env` file and then build and start the containers. This might take a few minutes the first time.

<Callout type="info">
  By default, we assume you are on a blank VPS and automatically setup a Caddy webserver. If you want to use your own webserver, checkout the [Advanced Self-Hosting Guide](/docs/self-hosting-advanced#using-your-own-web-server).
</Callout>

### 5. Sign Up

Once the services are running and DNS has propagated, Caddy (the webserver) will automatically obtain an SSL certificate for your domain.

Open your browser and navigate to `https://your.domain.name/signup` (using the domain you provided to the setup script).

Create your admin account. You can then log in and start adding your websites!

</Steps>

## Managing Your Installation

Rybbit comes with several helper scripts to manage your installation:

<Callout type="info">
  If you haven't done so already, make sure all scripts are executable:
  ```bash
  chmod +x *.sh
  ```
</Callout>

- **start.sh**: Start all services after they've been stopped
  ```bash
  ./start.sh
  ```

- **stop.sh**: Stop all running services
  ```bash
  ./stop.sh
  ```

- **restart.sh**: Restart all services
  ```bash
  ./restart.sh
  ```

- **update.sh**: Update to the latest version by pulling new code and rebuilding containers
  ```bash
  ./update.sh
  ```

<Callout>
If you are using your self-hosted Rybbit without anyone else, you can disable new user signups by setting `DISABLE_SIGNUP=true` in the `.env` file at the root of the repository.
</Callout>
{/* 
## Security Recommendation: Firewall Configuration

For enhanced security, it is highly recommended to configure a firewall on your VPS. Allow incoming connections only on the ports necessary for the application to function externally. In most standard setups, this means allowing traffic only on port `443` (HTTPS).

The exact commands depend on the firewall software used (e.g., `ufw` for Ubuntu, `firewalld` for CentOS).

Example using `ufw` (Uncomplicated Firewall) on Ubuntu:
```bash
sudo ufw allow ssh   # Keep SSH access (usually port 22)
sudo ufw allow 443/tcp # Allow HTTPS traffic
sudo ufw enable     # Enable the firewall
sudo ufw status     # Check the status
```

<Callout type="warning">
Ensure you allow SSH access (typically port 22) before enabling the firewall, otherwise you might lock yourself out of your VPS!
</Callout> */}

If you run into any issues or need help, feel free to join our Discord community!
